package com.tencent.wxcloudrun.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tencent.wxcloudrun.config.ApiResponse;

/**
 * @Author ZhaoZiYin
 * @Date 2025/4/30
 * @Description 全局异常处理
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public ApiResponse handleBusinessException(BusinessException ex) {
        return ApiResponse.error(ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ApiResponse handleAllExceptions(Exception ex) {
        log.error(ex.getMessage(), ex);
        return ApiResponse.error("系统繁忙，请稍后再试");
    }

}
